<template>
  <div>
    <el-form ref="form" :model="childBlogData" label-width="80px" size="mini">
      <el-form-item label="标题">
        <el-input v-model="childBlogData.blogTitle" />
      </el-form-item>
      <el-form-item label="分类">
        <el-select v-model="childBlogData.blogType" clearable filterable placeholder="请选择" style="width: 100%">
          <el-option
            v-for="type in typeList"
            :key="type.typeId"
            :label="type.typeName"
            :value="type.typeId"
          />
        </el-select></el-form-item>
      <!-- <el-form-item label="封面">
        <el-upload
          class="avatar-uploader"
          :action="uploadUrl"
          :show-file-list="false"
          :on-success="uploadSuccess"
          :headers="headers"
        >
          <img v-if="imageUrl" :src="imageUrl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon" />
        </el-upload>
      </el-form-item> -->
      <el-form-item label="内容">
        <tinymce v-model="childBlogData.blogContent" />
      </el-form-item>
      <el-form-item label="备注">
        <el-input v-model="childBlogData.blogRemark" type="textarea" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="onSubmit">提交</el-button>
        <el-button size="mini" @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import Tinymce from "@/components/Tinymce/index";

import blogApi from "@/api/blog";
import typeApi from "@/api/type";

export default {
  props:{
    childBlogData:Object
  },
  components: {
    Tinymce,
  },
   data() {
    return {
      typeList:[]
       
    };
  },
  created(){
     this.getTypeList()
  },
  methods:{
    //请求查询分类
     getTypeList(){
        typeApi.getTypeList().then(response =>{
          this.typeList = response.data.typeList
        })
     },
     onSubmit() {
      blogApi.updateOne(this.childBlogData).then((response) => {
         this.childBlogData = {}
        this.$message({
          message: "保存成功",
          type: "success",
        });
       this.$emit('closeUpdateDialog','false')         //子组件向父组件发消息
      });
    },
    cancel(){
     this.$emit('closeUpdateDialog','false')   
    }
  }
}
</script>
<style>
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
